<?php


class Component extends Object
{
    var $_Error;

    var $_Components;

    function __construct()
    {
        Vault::Add('Component', &$this);

        $this->_Error = &Vault::Get('Debug_Error');
    }

    function Run($application, $extension, $method, $args)
    {
        $this->_Load($application, $extension);
        return call_user_func_array(array(&$this->_Components[$application][$extension], $method), $args);
    }

    function _Load($application, $extension)
    {
        if (!isset($this->_Components[$application][$extension]))
        {
            using('Extensions.'.$application.'.'.$extension.'.component');

            if (class_exists(($class = 'Component_'.$application.'_'.$extension)))
            {
                $this->_Error->Log('Component :: Loading \''.$class.'\'', W_LOG_DEBUG);
                $this->_Components[$application][$extension] = new $class();
            }
            else
            {
                $trace = debug_backtrace();
                $this->_Error->Log('Component :: Error Loading \''.$class.'\' requested by \''.str_replace(W_ENV_PATH, '', $trace[1]['file']).':'.$trace[1]['line'].'\'', W_LOG_CRIT);
            }
        }
    }
}

?>